/**
 * 片区回款类型分析
 * zty
 * 2017-02-20
 */
(function () {
	var serverData = {};
    var	serverTable;
    //查询
    jQuery('#search_btn').on('click',function(){
    	 var beginPaidDate = jQuery('#nian').val()+"-"+jQuery('#yue').val()+"-"+1;//开始时间
         //如果为12月，年进1
         if(parseInt(jQuery('#yue').val())==12){
         	var endPaidDate = (parseInt(jQuery('#nian').val())+1)+"-"+01+"-"+01;
         }else{
         	var endPaidDate = (jQuery('#nian').val())+"-"+(parseInt(jQuery('#yue').val())+1)+"-"+01;
         }
         serverData.beginPaidDate=beginPaidDate;
         serverData.endPaidDate=endPaidDate;
         serverTable.draw();
	});
	
    jQuery(document).ready(function () {
    	var date = new Date();
    	//本月1日
    	var beginPaidDate = date.getFullYear()+"-"+(date.getMonth()+1)+"-01";
    	if(date.getMonth()+1 == 12){
    		//12月年+1；为明年1月1日
    		var endPaidDate = (date.getFullYear()+1)+"-01-01";
    	}else{
    		var endPaidDate = date.getFullYear()+"-"+(date.getMonth()+2)+"-01";
    	}
    	serverData.beginPaidDate=beginPaidDate;
        serverData.endPaidDate=endPaidDate;
        
        /*
    	 * 获取年份z
    	 */
    	var sel = document.getElementById('nian');
    	var date = new Date();
    	
    	for(var j=2;j>=0;j--){
    		var opt = document.createElement('option');
    		opt.value = date.getFullYear()+j;
    		opt.innerHTML = date.getFullYear()+j;
    		sel.appendChild(opt);
    		if(j==0){
    			opt.selected="selected"
    		}
    	}
    	for(var i=0;i<6;i++)
    	{
    		var opt = document.createElement("option");
    		opt.value = (date.getFullYear()-i-1);
    		opt.innerHTML = (date.getFullYear()-i-1);
    		sel.appendChild(opt);
    	}
    	 /*
    	  * 获取月份
    	  */
    	var mm = document.getElementById('yue');
    	 for(var k=1;k<=12;k++){
    		 var opt = document.createElement("option");
     		opt.value = k;
     		opt.innerHTML = k;
    		mm.appendChild(opt);
    		if(date.getMonth()+1 == k){
     			opt.selected="selected"
     		}
    	 }
    	 
    	 var beginPaidDate = jQuery('#nian').val()+"-"+jQuery('#yue').val()+"-"+1;//开始时间
         //如果为12月，年进1
         if(parseInt(jQuery('#yue').val())==12){
         	var endPaidDate = (parseInt(jQuery('#nian').val())+1)+"-"+01+"-"+01;
         }else{
         	var endPaidDate = (jQuery('#nian').val())+"-"+(parseInt(jQuery('#yue').val())+1)+"-"+01;
         }
         serverData.beginPaidDate=beginPaidDate;
         serverData.endPaidDate=endPaidDate;
        
        serverTable = jQuery('#dataTable').DataTable({
        	"serverSide": true,
        	"ordering": false,
        	"ajax": {
        		"dataType": "json",
        		"type": "post",
        		"cache": false,
        		"url":window.rootPath+ '/ui/analyzeArea/getMyTrance',
        		"pageLength" : -1,
        		"data": function (d) {
        			return $.extend({}, d, serverData);
        		}
        	},
        	"columns" : [{
  							data: null,
  							defaultContent  : ""// 排序   1
  						},
  						{
				        	 	data: 'sAreaName'//片区
			            },
			            {
			                data: 'sszjadvance'//实收主机预付款
			            },
			            {
			                data: 'sszjinterim'//实收主机进度款   
			            },
			            {
			                data: 'sszjpayment'//实收主机发货款 
			            },
			            {
				        	data: 'sszjacceptance'//实收主机验收款
			            },
			            {
			            	data: 'sszjdebug',//实收主机验收款
			            },
			            {
			                data: 'sszjquality'//实收主机质保金
			            },
			            {
			                data: 'sszjfreight' 
			            },
			            {
			                data: 'sszjtotal'//实收主机合计
			            },
			            
			            {
			            	data: 'yszjadvance'//应收主机预付款	
			            },
			            {
			            	data: 'yszjinterim'
			            },
			            {
			            	data: 'yszjpayment'	
			            },
			            {
			            	data: 'yszjacceptance'	
			            },
			            {
			            	data: 'yszjdebug'
			            },
			            {
			            	data: 'yszjquality',
			            },
			            {
			            	data: 'yszjfreight'//应收主机运费
			            },
			            {
			            	data: 'yszjtotal'//应收主机合计
			            },
			            {
			            	data: 'zjssbl'//主机比例
			            },
			            {
			            	data: 'ssbjadvance'//实收备件预付款	
			            },
			            {
			            	data: 'ssbjinterim'
			            },
			            {
			            	data: 'ssbjpayment'	
			            },
			            {
			            	data: 'ssbjacceptance'	
			            },
			            {
			            	data: 'ssbjdebug'
			            },
			            {
			            	data: 'ssbjquality',
			            },
			            {
			            	data: 'ssbjfreight'
			            },
			            {
			            	data: 'ssbjtotal'//实收备件合计	
			            },
			            
			            {
			            	data: 'ysbjadvance'//应收备件预付款  		
			            },
			            {
			            	data: 'ysbjinterim'
			            },
			            {
			            	data: 'ysbjpayment' 		
			            },
			            {
			            	data: 'ysbjacceptance' 		
			            },
			            {
			            	data: 'ysbjdebug'
			            },
			            {
			            	data: 'ysbjquality',
			            },
			            {
			            	data: 'ysbjfreight'
			            },
			            {
			            	data: 'ysbjtotal'//应收备件合计	
			            },
			            {
			            	data: 'bjssbl'//备件比例	
			            }],
            "drawCallback": function (oSettings) {
                var k = 0;
                var total = oSettings.aiDisplay.length + oSettings._iDisplayStart;

                for (var i = oSettings._iDisplayStart, iLen = total; i < iLen; i++) {
                    $('td:eq(0)', oSettings.aoData[oSettings.aiDisplay[k]].nTr).text(i + 1);
                    k++;
                }
            }
        		
 
            
        });

    	 
    });
    
    
    
})();